package com.linglan.bff.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.linglan.bff.vo.app.hospital.HospitalVO;
import com.linglan.common.api.R;
import com.linglan.modules.hospital.dto.result.HospitalResult;
import com.linglan.modules.hospital.service.BizHospitalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 医院相关业务模块
 */
@RestController
@RequestMapping("/app/hospitals")
@Slf4j
public class HospitalController {
    @Resource
    private BizHospitalService hospitalService;

    /**
     * 获取默认医院
     *
     * @return
     */
    @GetMapping("/default")
    @SaIgnore
    public R<HospitalVO> getCurrentHospital() {
        HospitalResult hospitalResult = hospitalService.findDefault();
        if (hospitalResult == null) {
            log.error("默认医院不存在");
            return R.failed("医院不存在");
        }
        HospitalVO vo  = new HospitalVO();
        vo.setId(hospitalResult.getId().toString());
        vo.setName(hospitalResult.getName());
        vo.setAddress(hospitalResult.getAddress());
        vo.setLat(hospitalResult.getLat().toString());
        vo.setLng(hospitalResult.getLng().toString());
        return R.ok(vo);
    }
}
